package simple_factory

import (
	"fmt"
)

// 定义房门接口
type Door interface {
	GetWidth() int
	GetHeight() int
}

// 木门
type WoodDoor struct {
	Width  int
	Height int
}

func (r *WoodDoor) GetWidth() int {
	return r.Width
}
func (r *WoodDoor) GetHeight() int {
	return r.Height
}

// 铁门
type IronDoor struct {
	Width  int
	Height int
}

func (r *IronDoor) GetWidth() int {
	return r.Width
}

func (r *IronDoor) GetHeight() int {
	return r.Height
}

// 工厂函数
func DoorFactory(doorType string, width, height int) (Door, error) {
	switch doorType {
	case "wood":
		return &WoodDoor{Width: width, Height: height}, nil
	case "iron":
		return &IronDoor{Width: width, Height: height}, nil
	default:
		return nil, fmt.Errorf("invalid doorType : %s", doorType)
	}
}
